package test;

import sdljava.* ;
import sdljava.joystick.* ;

public class Main {

    public static void main(String[] argv){
        try {
            SDLVersion version = SDLMain.getSDLVersion();
            {
                String versionString = String.format("SDL Version %d.%d.%d",version.getMajor(),version.getMinor(),version.getPatch());
                System.out.println(versionString);
            }
            int sticks = SDLJoystick.numJoysticks();
            {
                StringBuilder string = new StringBuilder();
                string.append("SDL found ");
                string.append(sticks);
                string.append(" joysticks");
                for (int cc = 0; cc < sticks; cc++){
                    if (0 == cc)
                        string.append(": ");
                    else
                        string.append(", ");
                    string.append(SDLJoystick.joystickName(cc));
                }
                System.out.println(string);
            }
            if (0 != sticks){
                try {
                    SDLMain.init(SDLMain.SDL_INIT_JOYSTICK);
                    Joystick.main();
                }
                catch (SDLException exc){
                    exc.printStackTrace();
                }
            }
            else {
                try {
                    SDLMain.init(SDLMain.SDL_INIT_VIDEO);
                    Events.main();
                }
                catch (SDLException exc){
                    exc.printStackTrace();
                }
            }
        }
        catch (Exception exc){
            exc.printStackTrace();
            System.exit(1);
        }
    }
}
